package Thread;

public class Demo15 {
    //使用这个锁对象负责加锁,wait notify
    private static final Object locker = new Object();

    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
        while(true){
            synchronized (locker){
                System.out.println("t1 wait 开始");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 wait 结束");
            }
        }
        });
        t1.start();
        Thread t2 = new Thread(()->{
            while(true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locker){
                    System.out.println("t2 notify 开始");
                    locker.notify();
                    System.out.println("t2 notify 结束");
                }
            }

        });
        t2.start();
    }
}
